import 'package:flutter/material.dart';

///页面父组件布局

///页面加载状态
enum LoadStatus { LOADING, FINISHED, ERROR, EMPTY }

///带有加载状态的widgets
class LoadingWidget extends StatelessWidget {
  final LoadStatus status;
  final Widget child;
  final TextStyle? notifyStyle;

  LoadingWidget({required this.status,required this.child,this.notifyStyle});

  @override
  Widget build(BuildContext context) {
    switch (status) {
      case LoadStatus.LOADING:
        return loading();
      case LoadStatus.FINISHED:
        return child;
      case LoadStatus.EMPTY:
        return empty();
      case LoadStatus.ERROR:
        return error();
    }
  }

  ///加载widget
  Widget loading() {
    return Container(
      width: double.infinity,
      height: double.infinity,
      child: CircularProgressIndicator(),
      alignment: Alignment.center,
    );
  }

  ///数据为空widget
  Widget empty() {
    return Container(
      width: double.infinity,
      height: double.infinity,
      alignment: Alignment.center,
      child: Text(
        '空空如也~',
        style: notifyStyle,
      ),
    );
  }

  Widget error() {
    return Container(
      alignment: Alignment.center,
      width: double.infinity,
      height: double.infinity,
      child: Text(
        '加载出错~',
        style: notifyStyle,
      ),
    );
  }
}

///hero 动画布局
class HeroWidget extends StatelessWidget {
  final String tag;
  final Widget child;

  HeroWidget({required this.tag,required this.child});

  @override
  Widget build(BuildContext context) {
    return Hero(tag: tag, child: child);
  }
}

